package com.boatAnchorAssistant.service.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.boatAnchorAssistant.pojo.entity.Resource;
import com.boatAnchorAssistant.service.mapper.ResourceMapper;
import com.boatAnchorAssistant.service.repository.in.ResourceRepository;
import nirvana.core.repository.Repository;
import org.springframework.stereotype.Service;
    import com.boatAnchorAssistant.pojo.dto.resource.*;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
* 【描 述】：
* 【环 境】：J2SE
* 【详 细】：
*
*/
@Service
public class ResourceRepositoryImpl extends Repository< ResourceMapper , Resource> implements ResourceRepository {

private final ResourceMapper mapper;

public ResourceRepositoryImpl(ResourceMapper mapper) {
this.mapper = mapper;
}

    /**
    * 搜索资源
    * @param dto
    * @return
    */
    @Override
    public Page< Resource > selectResource(SelectResourceDto dto){

    return mapper.selectResource(dto);
    }

    /**
     * 批量获取按钮资源
     *
     * @param ids
     * @return
     */
    @Override
    public List<Resource> getButtonResourceListByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        LambdaQueryWrapper<Resource> wrapper = getLambdaWrapper(new Resource());
        wrapper.in(Resource::getType, 3);
        wrapper.in(Resource::getId, ids);
        return mapper.selectList(wrapper);
    }

    /**
     * 批量获取页面资源
     *
     * @param ids
     * @return
     */
    @Override
    public List<Resource> getPageResourceListByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        LambdaQueryWrapper<Resource> wrapper = getLambdaWrapper(new Resource());
        wrapper.in(Resource::getType, 1, 2);
        wrapper.in(Resource::getId, ids);
        return mapper.selectList(wrapper);
    }

}